package top.yiciyuan.web.servlet;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import top.yiciyuan.web.dao.SupDao;
import top.yiciyuan.web.dao.SuperDaoImpl;
import top.yiciyuan.web.domain.Data;



public class ApiServlet extends BaseBackServlet {
		
	SupDao dao = new SuperDaoImpl();
	static List<Map> datas = null;
	public ApiServlet() {
		super();
		System.out.println("开始执行查询地图map数据>>>>>>>>>>>>>>>>>>"+new Date());
		new Runnable() {
			
			@Override
			public void run() {
				datas =  dao.getStudentMap();
				System.out.println("查询地图map数据完成<<<<<<<<<<<<<<<<"+new Date());
			}
		};
	}

	/**
	 * api 1
	 * 让用户搜索、学校、地点所匹配的学生信息
	 * 性别			学院			入学年	J值
	 * F	 	管理与经济学院	2018	8
	 */
	public String serarchStudent(HttpServletRequest request, HttpServletResponse response) {
		String university = request.getParameter("university");
		List<Data> datas = dao.serarchStudent(university);
		return JSONArray.fromObject(datas).toString();
	}
	
	/**
	 * api 2
	 * 按照学校所在城市来统计学生人数两个维度 来呈现分析结果。
	 * ['2012','2013','2014','2015','2016','2017','2018']
	 * [11, 21, 15, 13, 12, 13, 10]
	 */
	public String showStudentNumber(HttpServletRequest request, HttpServletResponse response) {
		String university = request.getParameter("university");
		List<List> datas = dao.showStudentNumber(university);
		return JSONArray.fromObject(datas).toString();
	}
	
	/**
	 * api 3
	 * 以地图分布的形式呈现学生数目分布。查出每个学校的学生数
	 * [
	 *  {name: '海门', value: 9},
	 *  {name: '鄂尔多斯', value: 12}
	 * ]
	 */
	public String getStudentMap(HttpServletRequest request, HttpServletResponse response) {
		while (datas != null) {
			return JSONArray.fromObject(datas).toString();
		}
		return null;		
	}
}
